package com.webdemo9.contrller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.webdemo9.dao.UsersDao;
import com.webdemo9.dao.impl.UsersDaoFactory;
/**
 * 删除用户
 * @author lovemanai
 *
 */
public class Delete extends HttpServlet {

	private UsersDao usersDao = UsersDaoFactory.getUsersDao();
	
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String username = request.getParameter("username");
		if(username.equals(request.getSession().getAttribute("username"))) {
			response.sendRedirect("listUsers?errorcode=6");
			return;
		}
		if(usersDao.delete(username) != 0) {
			response.sendRedirect("listUsers");
		}
	}

}
